from . import view
from . import schema
from fastapi import APIRouter, Security
from package.fastapi import permission


router_journal = APIRouter(prefix='/journal', tags=['系统日志'])
router_meta = {'module': '系统管理', 'sub_module': '系统日志'}


@router_journal.post('/audit', openapi_extra=router_meta, name='audit_get', summary='系统审计获取')
def audit_get(body: dict,
              page: int = 1,
              page_size: int = 10,
              user=Security(permission.security, scopes=['audit:read'])):
    return view.audit.get(body, page=page, page_size=page_size)


@router_journal.delete('/audit', openapi_extra=router_meta, name='audit_delete', summary='系统审计删除')
def audit_delete(body: schema.BatchId,
                 user=Security(permission.security, scopes=['audit:write'])):
    return view.audit.delete(body.ids)


@router_journal.post('/event', openapi_extra=router_meta, name='event_get', summary='系统事件获取')
def event_get(body: dict,
              page: int = 1,
              page_size: int = 10,
              user=Security(permission.security, scopes=['event:read'])):
    return view.event.get(body, page=page, page_size=page_size)


@router_journal.delete('/event', openapi_extra=router_meta, name='event_delete', summary='系统事件删除')
def event_delete(body: schema.BatchId,
                 user=Security(permission.security, scopes=['event:write'])):
    return view.event.delete(body.ids)
